#ifndef _A_LOG_H
#define _A_LOG_H

#ifdef __cplusplus
extern "C" {
#endif


//#include "config.h"

#define _LOG_OPEN    1


#define LOG_APP_PATH "."

// definition of log level
typedef enum _ENUM_LOG_LEVEL 
{
	LOGL_DEFAULT    = 00,   // default level
	LOGL_TRACE      = 01,   // trace message ,in-out functions
	LOGL_DEBUG      = 02,   // debug message [DEBUG]
	LOGL_INFO       = 04,   // information message
	LOGL_NOTICE     = 010,  // notice message
	LOGL_WARN       = 020,  // warning message [RELEASE]
	LOGL_ERROR      = 040,  // error message
	LOGL_FATAL      = 0100  // fatal message
}ENUM_LOG_LEVEL;

typedef enum _ENUM_LOG_MODE // definition of log destination
{
	LOG_OUTPUT_DEFAULT    = 00,   // default option
	LOG_OUTPUT_FILE       = 01,   // log to local file
	LOG_OUTPUT_STDOUT     = 02,   // log to standard output
	LOG_OUTPUT_STDOUT_FILE= 03,   // log to standard output
	LOG_OUTPUT_NETWORK    = 04    // log to network, no support
}ENUM_LOG_MODE;

struct clog_t;

int log_init(struct clog_t *plog,const char* fname);
int log_clean(struct clog_t *plog);

int log_set_level(struct clog_t *plog, ENUM_LOG_LEVEL level);
int	log_set_mode(struct clog_t *plog, ENUM_LOG_MODE mode);

void log_trace(struct clog_t *plog, ENUM_LOG_LEVEL level,const char *format,...);
void log_trace_octect(struct clog_t *plog, ENUM_LOG_LEVEL level, char *data, int count);

//single save buffer to bin file
int write_buffer_file(const char *filename, char *buffer, int size);


#ifdef _LOG_OPEN 
extern struct clog_t global_log;
#define LOGTRACE(level,...)		do { log_trace (&global_log,level,__VA_ARGS__);} while(0)
#define LOGTRACE_OCT(level, data, count)		do { log_trace_octect (&global_log,level, data, count);} while(0)
#else
#define LOGTRACE(level,...)	
#define LOGTRACE_OCT(level,...)	
#endif


#ifdef __cplusplus
}
#endif 

#endif // defined(_A_LOG_H)
